﻿@using Webdiyer.WebControls.Mvc;
@model PagedList<Magicodes.WeiChat.Data.Models.CMS.Column_Manage>

@{
    ViewBag.Title = "栏目管理";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-9">
        <h2>@ViewBag.Title</h2>
        <ol class="breadcrumb">
            <li>
                <a href="/">主页</a>
            </li>
            <li class="active">
                <strong>@ViewBag.Title</strong>
            </li>
        </ol>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <hr style="margin:2px 2px 10px 2px;" />
                    <div class="row">
                        <div class="col-sm-3">
                            @using (Html.BeginForm("Index", @Request.RequestContext.RouteData.GetRequiredString("controller"), FormMethod.Get))
                            {
                                <div class="input-group">
                                    @Html.TextBox("q", ViewBag.q as string, new { @placeholder = "请输入关键字", @class = "input-sm form-control" })
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button>
                                    </span>
                                </div>
                            }
                        </div>
                        <a class="btn btn-primary btn-sm" href="@Url.Action("Create")" id="btnAdd"><i class="fa fa-plus"></i>&nbsp;新建</a>
                        <a class="btn btn-warning btn-sm" id="btnDelete" data-action="Delete" data-comfirmmessage="确定删除所选内容么？"><i class="fa fa-remove"></i>&nbsp;批量删除</a>
                    </div>
                    <div>
                        <table class="table table-striped table-bordered table-hover" style="overflow-x:scroll">
                            <tr>
                                <th>
                                    <input type="checkbox" name="checkAll" id="chkCheckAll" class="i-checks" />
                                </th>
                                <th>
                                    @Html.DisplayNameFor(model => model.ColumName)
                                </th>
                                <th>
                                    @Html.DisplayNameFor(model => model.CreateTime)
                                </th>
                                <th>操作</th>
                            </tr>
                            @if (Model.Count == 0)
                            {
                                <tr>
                                    <td colspan="4" style="text-align:center;">
                                        <label>没有数据</label>
                                    </td>
                                </tr>
                            }
                            else
                            {
                                foreach (var item in Model)
                                {
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="ids" class="i-checks" value="@(item.Id)" />
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.ColumName)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.CreateTime)
                                        </td>
                                        <td>
                                            <div class="btn-group">
                                                @if (item.IsOnePage)
                                                {
                                                    <a class="btn btn-white" href="@Url.Action("EditContent", new { id = item.Id })">内容编辑</a>
                                                }
                                                else
                                                {
                                                    <a class="btn btn-white" href="@Url.Action("Create","Article_Manage", new { id = item.Id })">添加文章</a>
                                                }
                                                <a class="btn btn-white" href="@Url.Action("Edit", new { id = item.Id })">修改</a>                                                
                                                <button class="btn btn-white pull-right" data-myid="@item.Id" name="delete"><i class="fa fa-remove"></i>删除</button>
                                            </div>
                                        </td>
                                    </tr>
                                }
                            }                            
                        </table>
                    </div>
                    <div class="row">
                        @Html.Partial("_BootStrapPager", Model)
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section Styles {
    @Styles.Render("~/Content/plugins/iCheck/iCheckStyles")
}
@section Scripts {
    @Scripts.Render("~/plugins/iCheck")
    <script type="text/javascript">
        $(function () {
            mwc.bs.init();
            $('button[name=delete]').on('click', function () {
                mwc.message.confirm("确定要删除么？", "警告", function (result) {
                    console.log(result);
                    var $btn = $('button[name = delete]');
                    if (result) {
                        mwc.ui.setBusy();

                        $.ajax({
                            url: '/Column_Manage/Delete',
                            type: 'DELETE',
                            data: { id: $btn.data('myid') },
                            success: function (msg) {
                                if (!msg.Success) {
                                    toastr.error('警告', msg.Message);
                                    setTimeout(function () {
                                        location.reload();
                                    }, 3000);
                                } else {
                                    toastr.success('温馨提示', msg.Message);
                                    setTimeout(function () {
                                        location.reload();
                                    }, 1000);
                                }
                            }
                        });
                    }
                });
            });
        });        
    </script>
}

